home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / nss_fasttrack.idb / var / netscape / fasttrack / js / samples / videoapp / url.js.z / url.js
Text File  |  1998-10-13  |  3KB  |  113 lines

  1. /* ============================================================
  2.  
  3. FUNCTION:      spaceToplus( mystring )
  4.  
  5. INPUT:      mystring - the string to be converted
  6.  
  7. RETURNS:      the string after it has been processed
  8.  
  9. DESCRIPTION:       This function converts any spaces in 'mystring' to a + character.
  10.         This function is used to partially URL encode strings so that 
  11.         they may be used in a URL as part of an HTTP GET request 
  12.    
  13.         (e.g. http://www..../videos.html?Science+Fiction )
  14.     
  15.         This function could be expanded to do complete URL encoding, which
  16.         would include escaping other illegal characters.
  17.  
  18. ============================================================ */
  19.  
  20.  
  21. function spaceTOplus ( mystring )
  22. {
  23.     var resultstr = ""
  24.  
  25.     for (i = 0; i < mystring.length; i++)
  26.     {
  27.         if (mystring.charAt(i) == " ") {
  28.             resultstr += "+";
  29.         } else {
  30.             resultstr += mystring.charAt(i);
  31.         }
  32.     }
  33.     return resultstr;
  34.     
  35. }
  36.  
  37.  
  38. /* ============================================================
  39.  
  40. FUNCTION:      dayString( dayNum )
  41.  
  42. INPUT:      dayNum - a number from 0-6 that represents a day of the week
  43.  
  44. RETURNS:      the string representation of dayNum 
  45.  
  46. DESCRIPTION:     This function takes a number from 0-6, usually generated by
  47.         the JavaScript "getDay()" method, and converts it into the
  48.         corresponding string for that day.  So, if dayNum is 0
  49.         the function returns "Sunday", if daynum is 1 the function
  50.         returns "Monday", etc.
  51.  
  52. ============================================================ */
  53.  
  54. function dayString ( dayNum )
  55. {
  56.  
  57.     var resultstr = ""
  58.  
  59.     if (dayNum == 0) {
  60.         resultstr = "Sunday";
  61.     } else 
  62.     if (dayNum == 1) {
  63.         resultstr = "Monday";
  64.     } else 
  65.     if (dayNum == 2) {
  66.         resultstr = "Tuesday";
  67.     } else 
  68.     if (dayNum == 3) {
  69.         resultstr = "Wednesday";
  70.     } else 
  71.     if (dayNum == 4) {
  72.         resultstr = "Thursday";
  73.     } else 
  74.     if (dayNum == 5) {
  75.         resultstr = "Friday";
  76.     } else 
  77.     if (dayNum == 6) {
  78.         resultstr = "Saturday";
  79.     }
  80.  
  81.     return resultstr;
  82. }
  83.  
  84.  
  85. /* ============================================================
  86.  
  87. FUNCTION:      datetoString( mydate )
  88.  
  89. INPUT:      mydate - a date object
  90.  
  91. RETURNS:      a string representation of a date object
  92.  
  93. DESCRIPTION:       This function simply parses out each part of a date
  94.         object and returns the string representation of that date.
  95.         Note however that the time part of a date object (which
  96.         contains both date and time) is left out of the return string).
  97.  
  98. ============================================================ */
  99.  
  100. function datetoString ( mydate )
  101. {
  102.     var resultstr = ""
  103.  
  104.     resultstr += dayString(mydate.getDay()) + ", " +
  105.              (mydate.getMonth() + 1) + "/" +
  106.             mydate.getDate() + "/" +
  107.             mydate.getYear();
  108.  
  109.     return resultstr;
  110.  
  111. }
  112.  
  113.